<?php

namespace app\queue\stomp;

use app\queue\BaseConsumer;
use common\service\EntityRelationService;
use Webman\Stomp\RetryAbleConsumer;

/**
 * 同步概念的关联关系到资产和关卡中去
 * Class SyncDesignRelationData
 * @package app\queue\redis
 */
class SyncDesignRelationData extends BaseConsumer implements RetryAbleConsumer
{
    // 要消费的队列名
    public $queue = 'sync_design_relation_data';
    // 连接名，对应 config/redis_queue.php 里的连接`
    public $connection = 'default';

    /**
     * @param $data
     * @return void
     * @throws \Throwable
     */
    public function doConsume($data)
    {
        // 同步关联关系到下游实体 design => asset/level  storyboard=>shot/sequence
        EntityRelationService::getInstance()->syncRelationData(['id' => $data['id']], $data['module_code']);
    }

    /**
     * @return int
     */
    public function getTtr()
    {
        return 3;
    }

    /**
     * @param $attempt
     * @param $error
     * @return bool
     */
    public function canRetry($attempt, $error)
    {
        trace(format_exception_info($error), 'ERR');
        return $attempt <= 3;
    }
}
